package roboSoccer;

public class PbGoalie extends PlayerBehavior {

	public PbGoalie(RoboPlayer host) {
		super(host, "Goalie");
	}

	public boolean leaveState(GameState game) {
		return false;
	}

	public void update(GameState game) {
		if(host.position.distance(game.ball.position) > 100 ||
				host.position.distance(host.team.homeGoal.center()) > 200)
		{
			Vector defendLocation = Vector.add(host.team.homeGoal.center(),
					new Vector(host.team.homeGoal.center().vectorAngle(game.ball.position),
							host.team.homeGoal.b.y/2, true));
			host.controller.goToLocation(game, host, defendLocation, 3, 15, 0,
					RoboPlayer.sizeRadius + FieldObject.sizeRadius);
		
			host.controller.turnTowardsLocation(game, host, game.ball.position, 5, 0);
		}
		else
		{
			host.controller.goToLocation(game, host,
					game.ball.futurePosition((int) host.position.distance(game.ball.position)),
					3, 15, 0, RoboPlayer.sizeRadius + FieldObject.sizeRadius);
			host.controller.turnTowardsLocation(game, host, game.ball.position, 5, 0);
			if(host.position.distance(game.ball.position) < RoboPlayer.sizeRadius + FieldObject.sizeRadius*1.5)
				host.controller.kick(70);
		}
	}

}
